function simulasi(){
var index=document.ffrom.pilih.selectedIndex;
var pil=document.ffrom.pilih.options[index].value;
var bsr=parseFloat(document.ffrom.awal.value);
var bga=parseFloat(document.ffrom.bunga.value);
var lm=parseFloat(document.ffrom.lama.value);
switch(index){
case 0:
	var x="";
	var j,usaha,total,total_usaha=0;
	var total_pokok=bsr;
	var pokok=bsr/lm;
	var total_akhir=0;
	usaha=bsr*(bga/100);
	for (j=1; j<=lm; j++){
		bsr=bsr-pokok;
		if(j==lm){
			bsr=0;
				}
		total_usaha+=usaha;
		total=pokok+usaha;
		x= x+"<tr><td>"+j+"</td><td>Rp. "+pokok.formatMoney(2, '.', ',')+"</td><td>Rp. "+usaha.formatMoney(2, '.', ',')+"</td><td>Rp. "+total.formatMoney(2, '.', ',')+"</td><td>Rp. "+bsr.formatMoney(2, '.', ',')+"</td></tr>";
	}
		x=x+"<td><strong>Jumlah</strong></td><td><strong>Rp. "+total_pokok.formatMoney(2, '.', ',')+"</strong></td><td><strong>Rp. "+total_usaha.formatMoney(2, '.', ',')+"</strong></td><td><strong>Rp. "+(total_pokok+total_usaha).formatMoney(2, '.', ',')+"</strong></td><td></td>";
		document.getElementById("demo").innerHTML=x;
break;

case 1:
	var x="";
	var j,usaha,total,total_usaha=0;
	var total_pokok=bsr;
	var pokok=bsr/lm;
	var total_akhir=0;
	for (j=1; j<=lm; j++){

		usaha=bsr*(bga/100);
		bsr=bsr-pokok;
	if(j==lm){
		bsr=0;
				}
		total_usaha+=usaha;
		total=pokok+usaha;
		x= x+"<tr><td>"+j+"</td><td>Rp. "+pokok.formatMoney(2, '.', ',')+"</td><td>Rp. "+usaha.formatMoney(2, '.', ',')+"</td><td>Rp. "+total.formatMoney(2, '.', ',')+"</td><td>Rp. "+bsr.formatMoney(2, '.', ',')+"</td></tr>";
}
		x=x+"<td><strong>Jumlah</strong></td><td><strong>Rp. "+total_pokok.formatMoney(2, '.', ',')+"</strong></td><td><strong>Rp. "+total_usaha.formatMoney(2, '.', ',')+"</strong></td><td><strong>Rp. "+(total_pokok+total_usaha).formatMoney(2, '.', ',')+"</strong></td><td></td>";
	document.getElementById("demo").innerHTML=x;
break;

case 2:
	var x="";
	var j,usaha,total,total_usaha=0;
	var total_pokok=bsr;
	var pokok=0;
	var total_akhir=0;
		usaha=bsr*(bga/100);
	for (j=1; j<=lm; j++){
		bsr=bsr-pokok;
	if(j==lm){
	    pokok=bsr;
		bsr=0;
				}
	total_usaha+=usaha;
	total=pokok+usaha;
	x= x+"<tr><td>"+j+"</td><td>Rp. "+pokok.formatMoney(2, '.', ',')+"</td><td>Rp. "+usaha.formatMoney(2, '.', ',')+"</td><td>Rp. "+total.formatMoney(2, '.', ',')+"</td><td>Rp. "+bsr.formatMoney(2, '.', ',')+"</td></tr>";
	}
	x=x+"<td><strong>Jumlah</strong></td><td><strong>Rp. "+total_pokok.formatMoney(2, '.', ',')+"</strong></td><td><strong>Rp. "+total_usaha.formatMoney(2, '.', ',')+"</strong></td><td><strong>Rp. "+(total_pokok+total_usaha).formatMoney(2, '.', ',')+"</strong></td><td></td>";
	document.getElementById("demo").innerHTML=x;
break;

case 3:

var anuitas,anuitaspkt;
var x="";
var j,usaha,total,total_usaha=0,bunga,angs1;
var total_pokok=bsr;
var pokok=0;
var total_akhir=0;
bunga=bga/100;
anuitaspkt=Math.pow(1+bunga,-lm);
anuitas= (bsr*bunga)/(1-anuitaspkt);
angs1=anuitas-(bsr*bunga);
for (j=1; j<=lm; j++){
if(j==1){
usaha=bsr*bunga;
pokok=angs1;
}
else{
pokok=angs1*Math.pow(1+bunga,j-1);
usaha=anuitas-pokok;
}
	bsr=bsr-pokok;
	if(j==lm){
		bsr=0;
				}
total_usaha+=usaha;
total=pokok+usaha;
x= x+"<tr><td>"+j+"</td><td>Rp. "+pokok.formatMoney(2, '.', ',')+"</td><td>Rp. "+usaha.formatMoney(2, '.', ',')+"</td><td>Rp. "+total.formatMoney(2, '.', ',')+"</td><td>Rp. "+bsr.formatMoney(2, '.', ',')+"</td></tr>";
}
x=x+"<td><strong>Jumlah</strong></td><td><strong>Rp. "+total_pokok.formatMoney(2, '.', ',')+"</strong></td><td><strong>Rp. "+total_usaha.formatMoney(2, '.', ',')+"</strong></td><td><strong>Rp. "+(total_pokok+total_usaha).formatMoney(2, '.', ',')+"</strong></td><td></td>";

document.getElementById("demo").innerHTML=x;

break;
default : 
alert ("error");
break;
}
}

Number.prototype.formatMoney = function(c, d, t){
var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
   return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
 };
